#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <qgl.h>
#include <QHBoxLayout>
#include "demuxthread.h"
#include "glfullscreenwindow.h"

class GLWidget;

class RenderThread : public QThread
{
    Q_OBJECT
    GLWidget* screen;
    glFullScreenWindow* fsDisplay;
    Video* v;
    double videoLength;
public:
    RenderThread(GLWidget* screen = 0, glFullScreenWindow* fsDisplay = 0, Video* v = 0);
private:
    void run();
signals:
    void finishRender();
    void setSlider(int);
};

class DecodeThread : public QThread
{
    Q_OBJECT
    Video* v;
public:
    DecodeThread(GLWidget* screen = 0, Video* v = 0);
private:
    void run();
};

class GLWidget : public QGLWidget
{
    Q_OBJECT
private:
    glFullScreenWindow* fsDisplay;
protected:
    int volume;
    Video* v;
    DemuxThread* dmThread;
    DecodeThread* dcThread;
    RenderThread* reThread;
    AudioPlayer* aPlayer;

    void resizeEvent(QResizeEvent *evt);
    void paintEvent(QPaintEvent *);
    void closeEvent(QCloseEvent *evt);
    void mouseDoubleClickEvent(QMouseEvent *);

public:
    GLWidget(QWidget *parent = 0);
    ~GLWidget();
    void setFSWindow(glFullScreenWindow* fsDisplay);
    
    void initializeGL();
    void paintGL();
    void resizeGL(int w, int h);

    void loadVideo(QString vid_file_path);
    void clean();

public slots:
    void play(QString vid_file_path);
    void stop();
    void pause();
    void fastForward();
    void fastBackward();
    void skipForward();
    void skipBackward();

    void setVolume(int volume);
    void seek(int millentage);
signals:
    void setSlider(int);
};

#endif // GLWIDGET_H
